-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Allow hooks for backed readonly
properties
#18757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
1a21998
to
6840873
Compare
da64264
to
24f2687
Compare
c06c915
to
12b986a
Compare
readonly
propertiesreadonly
properties
Zend/tests/property_hooks/readonly_class_property_backed_inheritance_1.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_class_property_backed_inheritance_2.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_class_property_backed_promoted.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_class_property_backed_promoted.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_property_backed_trait_1.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_property_virtual_in_abstract.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/property_hooks/readonly_property_virtual_in_interface.phpt
Outdated
Show resolved
Hide resolved
Larry (@Crell) correctly pointed out that the error messages for Currently we have a single one for the both
There could be two:
We would appreciate opinions on that! 🙂 cc @TimWolla, because this is a follow up to your "misleading errors" change request. |
Zend/tests/property_hooks/readonly_property_backed_inheritance_1.phpt
Outdated
Show resolved
Hide resolved
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Hooked properties in abstract classes cannot be declared readonly in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one isn't better. My first review wasn't particularly precise in what was bothering me, though: I do not consider this to be a “hooked property”, since there is no actual hook. It just borrows the hook syntax to define the operations required by the interface, so calling this a “hook” is wrong in my book.
Just dropping the “Hooked” from the error message might be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the correct error message in this case would be:
Fatal error: Non-abstract property hook must have a body in %s on line %d
Since that would be emitted when the readonly
is removed. The readonly
isn't the main problem here, the missing hook body is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readonly isn't the main problem here, the missing hook body is.
Not sure if I am following here. In 8.4 we have:
Hooked properties cannot be 'readonly'
Non-abstract property hook must have a body
In 8.5 we would have:
Hooked properties in abstract classes cannot be declared readonly
Non-abstract property hook must have a body
I feel like I am testing exactly what I should test. I also feel the new error is perfectly fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An interface/abstract class declaring get
or set
doesn't imply hooks, just that those operations be valid. A normal, non-hooked property would satisfy that just as well.
I think the error messages should be something like:
interface I {
public readonly $foo { get; }
}
"Interface properties may not be readonly."
abstract class A {
abstract public readonly $foo { get; }
}
"Abstract properties may not be readonly."
class C {
public readonly $foo { get; }
}
"Non-abstract property hook must have a body."
(Arguably we could combine the first two into a single message about abstract properties. I don't care much either way.)
Tim, would that work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tim, would that work for you?
Yes. The important bit for me is the priority of the error messages. The missing body is the actual issue, not the readonly
. This should likely also fixed in PHP 8.4, since it's confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The important bit for me is the priority of the error messages. The missing body is the actual issue, not the
readonly
. This should likely also fixed in PHP 8.4, since it's confusing.
I pushed an update.
Concern: To me it looks like Ilija did chose the previous order so that it would error out early before even looping over hooks->children
. Now the loop runs always. Wdyt?
https://wiki.php.net/rfc/readonly_hooks
https://news-web.php.net/php.internals/127529